package com.frank.work;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author 小石潭记
 * @date 2021/12/21 10:10
 * @Description: ${todo}
 */
@Component
public class ApplicationContextProvider implements ApplicationContextAware {

    private static ApplicationContext applicationContextSpring;

    @Override
    public synchronized void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        applicationContextSpring = applicationContext;
    }

    /**
     * 根据名字获取bean
     */
    public Object getBeanByName(String name) {
        return applicationContextSpring.getBean(name);
    }
}
